package com.itheima.d1_file;

import java.io.File;
import java.io.IOException;

/*
        认识file类 掌握常见的方法
 */
public class FileDemo1 {
    public static void main(String[] args) throws IOException {
        // 1.创建File对象
        File f1 = new File("C:\\Program Files\\Java\\src");
        boolean f = f1.isFile();
        System.out.println(f);
        //File f2 = new File("C:\\Program Files\\Java","src");
        //File f3 = new File(f1,"b.txt");
//        File f4 = new File("C:\\Program Files\\Java\\src\\aa\\bb\\cc\\dd");
        //System.out.println(f1.length());//获取文件的字节个数
        System.out.println("======================");

        //2.可以使用绝对路径也可以使用相对路径
        File f2 = new File("day06-file-io\\src\\test01.txt");
        System.out.println(f2.getPath());
        System.out.println(f2.getAbsolutePath());//绝对路径带盘符
        System.out.println("===================================");

        //3.常用方法
        File f3 = new File("day06-file-io\\src\\test02.txt");
        System.out.println(f3.exists());//是否存在
        System.out.println(f3.lastModified());//最近修改的时间
        System.out.println(f3.getPath());//路径
        System.out.println(f3.createNewFile());//创建文件
        System.out.println("========================================");

        //4.创建对象代表不存在的文件夹路径
        File f4 = new File("day06-file-io\\fff");
        System.out.println(f4.mkdir());

        //5.创建对象代表不存在的多级文件夹路径
        File f5 = new File("day06-file-io\\fff\\ggg\\hhh");
        System.out.println(f5.mkdirs());
        System.out.println("===========================================");

        //6.创建File对象代表不存在的文件，删除
        System.out.println(f5.delete());//删除hhh
        File f6 = new File("day06-file-io\\test01.txt");
        System.out.println(f6.delete());

        System.out.println("===========================================");

        //7.遍历文件夹
        File f7 = new File("day06-file-io\\src");
        String[] list = f7.list();
        for (String s : list) {
            System.out.println(s);
        }

        File[] files = f7.listFiles();
        for (File file : files) {
            System.out.println( file.getAbsolutePath());
        }


    }

}
